//
// 设备配置界面
//

import QtQuick
import QtQuick.Controls.Material
import QtQuick.Layouts

Item {
    id: configDeviceWindowRoot
    width: 1080
    height: 1876

    Component.onCompleted: {
        // Cpp_PLC.QML_CurrentPage = 19;
        // Cpp_PLC.write_Modbus_RTU_Hold_16(48,"2")
    }

    // property bool m_528 : Cpp_PLC.M_528
    // property bool m_510 : Cpp_PLC.M_510
    // property bool m_509 : Cpp_PLC.PowerOffMode
    // property bool m_400 : Cpp_PLC.M_400
    // property bool m_398 : Cpp_PLC.M_398
    // property bool m_397 : Cpp_PLC.M_397
    // property bool m_396 : Cpp_PLC.AutoObserveState
    // property bool m_396 : Cpp_PLC.MechineChangeAngleMode
    // property bool m_500 : Cpp_PLC.M_500
    // property bool m_501 : Cpp_PLC.M_501
    // property bool m_392 : Cpp_PLC.ServoType
    // property bool m_393 : Cpp_PLC.M_393
    // property bool m_502 : Cpp_PLC.M_502
    // property bool m_503 : Cpp_PLC.M_503
    // property bool m_399 : Cpp_PLC.M_399
    // property bool m_529 : Cpp_PLC.M_529
    // property bool m_530 : Cpp_PLC.M_530




    ColumnLayout{
        anchors.left: configDeviceWindowRoot.left
        anchors.leftMargin: 100
        anchors.top: configDeviceWindowRoot.top
        anchors.topMargin: 100
        spacing: 40

        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_528 ? qsTr("工进时间分开") : qsTr("工进时间共用")
            contentRectangle_BorderWidth: Cpp_PLC.M_528 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_528 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_528 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(528,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(528,"1")
                }
            }

        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_510 ? qsTr("旋钮选择角度") : qsTr("旋钮选择机头")
            contentRectangle_BorderWidth: Cpp_PLC.M_510 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_510 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_510 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(510,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(510,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.PowerOffMode ? qsTr("电磁阀断电") : qsTr("电磁阀不断电")
            contentRectangle_BorderWidth: Cpp_PLC.PowerOffMode ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.PowerOffMode ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.PowerOffMode === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(509,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(509,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_400 ? qsTr("编码器17位") : qsTr("编码器21位")
            contentRectangle_BorderWidth: Cpp_PLC.M_400 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_400 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_400 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(400,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(400,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_398 ? qsTr("打印机存在") : qsTr("打印机不存在")
            contentRectangle_BorderWidth: Cpp_PLC.M_398 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_398 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_398 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(398,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(398,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_397 ? qsTr("托料架存在") : qsTr("托料架不存在")
            contentRectangle_BorderWidth: Cpp_PLC.M_397 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_397 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_397 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(397,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(397,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.AutoObserveState ? qsTr("自动测高存在") : qsTr("自动测高不存在")
            contentRectangle_BorderWidth: Cpp_PLC.AutoObserveState ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.AutoObserveState ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.AutoObserveState === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(396,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(396,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.MechineChangeAngleMode ? qsTr("45度内摆") : qsTr("45度外摆")
            contentRectangle_BorderWidth: Cpp_PLC.MechineChangeAngleMode ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.MechineChangeAngleMode ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.MechineChangeAngleMode === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(394,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(394,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_500 ? qsTr("急停按钮常闭") : qsTr("急停按钮常开")
            contentRectangle_BorderWidth: Cpp_PLC.M_500 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_500 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_500 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(500,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(500,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_501 ? qsTr("伺服报警常闭") : qsTr("伺服报警常开")
            contentRectangle_BorderWidth: Cpp_PLC.M_501 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_501 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_501 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(501,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(501,"1")
                }
            }
        }

    }

    ColumnLayout{
        anchors.right: configDeviceWindowRoot.right
        anchors.rightMargin: 100
        anchors.top: configDeviceWindowRoot.top
        anchors.topMargin: 100
        spacing: 40

        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.ServoType ? qsTr("绝对值伺服") : qsTr("增量式伺服")
            contentRectangle_BorderWidth: Cpp_PLC.ServoType ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.ServoType ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.ServoType === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(392,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(392,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_393 ? qsTr("触屏选择左右锯") : qsTr("旋钮选择左右锯")
            contentRectangle_BorderWidth: Cpp_PLC.M_393 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_393 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_393 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(393,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(393,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_502 ? qsTr("限位开关常闭") : qsTr("限位开关常开")
            contentRectangle_BorderWidth: Cpp_PLC.M_502 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_502 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_502 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(502,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(502,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_503 ? qsTr("机头旋钮常闭") : qsTr("机头旋钮常开")
            contentRectangle_BorderWidth: Cpp_PLC.M_503 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_503 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_503 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(503,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(503,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_529 ? qsTr("拉手启用") : qsTr("拉手禁用")
            contentRectangle_BorderWidth: Cpp_PLC.M_529 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_529 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_529 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(529,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(529,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_530 ? qsTr("45专切启用") : qsTr("45专切禁用")
            contentRectangle_BorderWidth: Cpp_PLC.M_530 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_530 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_530 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(530,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(530,"1")
                    Cpp_PLC.write_Modbus_RTU_Coils(13,"1")
                    Cpp_PLC.write_Modbus_RTU_Coils(13,"0")
                    Cpp_PLC.write_Modbus_RTU_Coils(14,"1")
                    Cpp_PLC.write_Modbus_RTU_Coils(14,"0")
                }
            }
        }


        A_Button{           // 505
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_505 ? qsTr("DVS伺服") : qsTr("TH伺服")
            contentRectangle_BorderWidth: Cpp_PLC.M_505 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_505 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_505 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(505,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(505,"1")
                }
            }
        }
        A_Button{
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_506 ? qsTr("锯片防扫料开") : qsTr("锯片防扫料关")
            contentRectangle_BorderWidth: Cpp_PLC.M_506 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_506 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_506 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(506,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(506,"1")
                }
            }
        }
        A_Button{           // M507
            buttonWidth: 400
            contentText_Data: Cpp_PLC.M_507 ? qsTr("压紧反逻辑") : qsTr("压紧正逻辑")
            contentRectangle_BorderWidth: Cpp_PLC.M_507 ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.M_507 ? "gold" : "black"

            onButtonClicked: {

                if(Cpp_PLC.M_507 === true)
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(507,"0")
                }
                else
                {
                    Cpp_PLC.write_Modbus_RTU_Coils(507,"1")
                }
            }
        }





    }


    A_TextInput{
        anchors.right: configDeviceWindowRoot.right
        anchors.rightMargin: 500
        anchors.bottom: configDeviceWindowRoot.bottom
        anchors.bottomMargin: 100

        showData: Cpp_PLC.DoubleSaws_StartDelay
        enabled: Cpp_PLC.M_399

        onInputFinished: {

            if(Number(inputData) < 0)
            {
                Cpp_PLC.write_Modbus_RTU_Hold_16(1562,"0")
            }
            else if(Number(inputData) > 20)
            {
                Cpp_PLC.write_Modbus_RTU_Hold_16(1562,"20")
            }
            else
            {
                Cpp_PLC.write_Modbus_RTU_Hold_16(1562,inputData)
            }
        }

    }



    A_Button{
        buttonWidth: 400
        anchors.right: configDeviceWindowRoot.right
        anchors.rightMargin: 100
        anchors.bottom: configDeviceWindowRoot.bottom
        anchors.bottomMargin: 100
        contentText_Data: Cpp_PLC.M_399 ? qsTr("双锯延时-已启用") : qsTr("双锯延时-已禁用")
        contentRectangle_BorderWidth: Cpp_PLC.M_399 ? 5 : 3
        contentRectangle_BorderColor: Cpp_PLC.M_399 ? "gold" : "black"

        onButtonClicked: {

            if(Cpp_PLC.M_399 === true)
            {
                Cpp_PLC.write_Modbus_RTU_Coils(399,"0")
            }
            else
            {
                Cpp_PLC.write_Modbus_RTU_Coils(399,"1")
            }
        }
    }






}
